import React, { Component } from 'react'
import PropTypes from 'prop-types'
import {
  Form,
  Input
} from 'antd'

const Item = Form.Item

/*
更新分类的form组件
 */
class UpdateForm extends Component {
  updateformRef=React.createRef();
  static propTypes = {
    categoryName: PropTypes.string.isRequired,
    setForm: PropTypes.func.isRequired
  }

  componentDidMount() {
    this.props.setForm(this.updateformRef.current);
    // console.log("componentDidMount",this.props);
    const { categoryName } = this.props;
    this.updateformRef.current.setFieldsValue({ categoryName});
  }

  render() {
    // console.log("UpdateForm-render",this.props);
    return (
      <Form ref={this.updateformRef}>
        <Item name="categoryName" rules={[
          { required: true, message: '分类名称必须输入' }
        ]}>
          <Input placeholder='请输入分类名称' />
        </Item>
      </Form>
    )
  }
}

export default (UpdateForm)